package com.clf.data.redis.core.json;


import com.alibaba.fastjson.JSON;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;

/**
 * fastjson解析器
* @author <a href="mailto:zhudelie@zuozh.com">zhudelie</a>
* @version 
* @since JDK 1.6
* create on 2017年3月31日
* Copyright 2017 ZZJR All Rights Reserved.
*
*/
abstract  class FastJsonSerializerAbstractor<T> implements RedisSerializer<T> {
	boolean autoRemoveConvert;
	public FastJsonSerializerAbstractor(){
		this(true);
	}
	public FastJsonSerializerAbstractor(boolean autoRemoveConvert){
		this.autoRemoveConvert = autoRemoveConvert;
	}

	@Override
	public byte[] serialize(T t) throws SerializationException {
		if(t == null){
			return null;
		}
		return JSON.toJSONBytes(t);
	}

	protected String bytes2String(byte[] bytes){
		return FastJsonSerializerStringPool.bytes2String(bytes);
	}

	@Override
	public  T deserialize(byte[] bytes) throws SerializationException {
		if(bytes == null){
			return null;
		}
		return deserialize0(bytes);
	}

	protected abstract  T deserialize0(byte[] bytes) throws SerializationException;
}
